package diamondRingServlet;

import diamondRingEntity.Admin;
import diamondRingService.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/*
添加用户
 */
@WebServlet("/BackAddAdminServlet")
public class BackAddAdminServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        AdminServiceImpl adminService=new AdminServiceImpl();

        int count = 0;
        String adminName = request.getParameter("adminName");
        System.out.println(adminName);

        String pwd = "1111";
        System.out.println(pwd);

        String adminsex = request.getParameter("adminsex");
        System.out.println(adminsex);
        String adminBrithday = request.getParameter("adminBrithday");
        System.out.println(adminBrithday);
        String adminPhone = request.getParameter("adminPhone");
        System.out.println(adminPhone);
        String adminAge = request.getParameter("adminAge");
        System.out.println(adminAge);
        String adminAdeessr = request.getParameter("adminAdeessr");
        System.out.println(adminAdeessr);

        Admin admin = new Admin(adminName,pwd,adminsex,adminAge,adminPhone,adminBrithday,adminAdeessr);

        if (adminService.InsertAdminInfo(admin)>0){
            count = 1;
        }else{
            count = -1;
        }
        out.print(count);
        out.flush();
        out.close();


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}